var express = require('express');
var query = require('./db');
var userRouter = express.Router();

userRouter.post('/user/login', function (req, res, next) {
    query(`select * from user where username='${req.body.username}' and pwd='${req.body.pwd}'`, function (err, result) {
        let obj={
            status:200,
            data:result
        }
        if(err){
            status=0;
            data=err;
            res.send(obj);
        }
        else{
            res.send(obj);
        }
    });
});

userRouter.get('/user',function(req,res,next){
    
    query(`select * from user where uid=${req.cookies.uid}`,function(err,result){
        let obj={
            status:200,
            data:result
        }
        if(err){
            status=0;
            data=err;
            res.send(obj);
        }
        else{
            res.send(obj);
        }
    });
})

module.exports = userRouter;